package day12;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.List;

/**
 * @author oldliu
 * @since 1.0
 */
public class JSONTest2 {
    //parse parseArray
    public static void main(String[] args) {
        String str="[{\"addr\":\"六安\",\"age\":21,\"marry\":false,\"name\":\"秋宏开\"},{\"addr\":\"hefei\",\"age\":25,\"marry\":true,\"name\":\"林超\"},{\"addr\":\"合肥\",\"age\":22,\"marry\":false,\"name\":\"周一文\"},{\"addr\":\"阜阳\",\"age\":21,\"marry\":false,\"name\":\"马聪宝\"}]";
        try {
            BufferedReader fr=new BufferedReader(new FileReader("people.json"));
            String s2="",s;
            while ((s=fr.readLine())!=null)
                s2+=s;
            List<People> parse = JSON.parseArray(s2,People.class);
            for(People p:parse){
                System.out.println(p);
            }
            System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
        } catch ( Exception e) {
            e.printStackTrace();
        }
        List<People> parse = JSON.parseArray(str,People.class);
        for(People p:parse){
            System.out.println(p);
        }
    }
}
